﻿/*
 *  Author: Louis A. Leskoviansky
 *  Company: Artemis Solutions Group (http://www.artemis-solutions.com)
 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AjaxControlFramework
{
    public class ScriptReferenceDependencyComparer : IComparer<ScriptReference>
    {
        //------// Methods \\-----------------------------------------------\\
        public int Compare(ScriptReference script1, ScriptReference script2)
        {
            int retVal = 0;

            if (script2.Dependencies.Contains(script1.Name))
            {
                retVal = -1;
            }

            if (script1.Dependencies.Contains(script2.Name))
            {
                if (retVal == -1)
                {
                    throw new InvalidOperationException("References to the scripts " + script1.Name + " and " + script2.Name + " share a circular dependency.");
                }

                retVal = 1;
            }

            return retVal;
        }
        //------\\ Methods //-----------------------------------------------//
    }
}
